<%-- 
    Document   : test
    Created on : Sep 9, 2011, 4:29:14 AM
    Author     : northpole
--%>

<%@page import="java.util.ArrayList"%>
<%@page import="user.User" contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <link type="text/css" rel="stylesheet" href="sidebar.css" media="screen" />

        <title>Profile Page</title>
<%User userInfo=null;
        userInfo = (User) session.getAttribute("userInfo");
        int privMode=-1;
        User stranger=new User();
        User friend=new User();
        ArrayList friends=null;
        String username=null,name=null,surname=null,date=null,welcomeText=null;
        String []interests=null;
        String requestUname=request.getParameter("username");

        if(requestUname==null)
          { //requestUname="nulll"; response.sendRedirect("ErrorPage.html");return;
            }
        if(session.getAttribute("username")==null)
        {
            //response.sendRedirect("ErrorPage.html");return;
        }
       // out.print("Welcome afadsf"+ request.getParameter("username"));
        if (requestUname.equals(session.getAttribute("username")))
            {//re-visit own profile
            out.print("Welcome "+session.getAttribute("username")+"");
               userInfo = (User) session.getAttribute("userInfo");
                privMode=1;
                //out.println("id " + session.getAttribute("id") + " </br>");
                name=session.getAttribute("name").toString();
                surname=session.getAttribute("surname").toString();
                interests=session.getAttribute("interests").toString().split(",");
               username=session.getAttribute("username").toString();
        //        welcomeText=session.getAttribute("welcomeText").toString();
                date=session.getAttribute("dateOfBirth").toString();

                userInfo.loadFriendList();
                friends=(ArrayList)session.getAttribute("friends");
               friends=userInfo.getFriendUsernames();
             
               
               }
        else if(!requestUname.equals(session.getAttribute("username"))){//visit not own profile
                        if(userInfo!=null && userInfo.isFriend(request.getParameter("username"))) //visiting a friend
                         {privMode=2;
                          
                          friend.setUsername(request.getParameter("username"));
                          friend.loadFriendInfo();
                          ArrayList inf=friend.getFriendInfo();
                        if(inf.size()==5)
                          {name=inf.get(0).toString();
                          surname=inf.get(1).toString();
                          date=inf.get(2).toString();
                          interests=inf.get(3).toString().split(",");
           //               welcomeText=inf.get(4).toString();
                            }
                        }
                        else if((userInfo!=null &&!userInfo.isFriend(request.getParameter("username"))))
                                {privMode=3;
                          if(stranger.getMisc().usernameExists(request.getParameter("username")))
                             {    stranger.setUsername(request.getParameter("username"));
                         stranger.loadPublicInfo();
                         ArrayList inf=stranger.getPublicInfo();
                        interests=inf.get(0).toString().split(",");
              //          welcomeText=inf.get(1).toString();
                        }
                        else
                            out.print("Non Existent Username");
                        }
        }
        %>
    </head>
    <body>
        <div id ="footbar">
            <div id="RightBar">
            	<br>
                <a href="endSession.jsp"><b>
                <input type="image" src="imadge/on-off.jpg" name="image" background-color="#C0C0C0" width="35" height="35" >
                    </b>
                </a>
            </div>
        </div>
 <div id="rightbar" class="sidebox">
     
     <table id="right">
           <tr> <td>
        <hr>
             <ul>

   <%
   if(privMode==1)
                { //if(userInfo.pendingFriendRequestsTo.length()>0)
                    //  {out.print(userInfo.pendingFriendRequestsTo.length()+" users want to be your friends");
                     // for(int i=0;i<userInfo.pendingFriendRequestsTo.length();i++)
                       //    out.print("<a href=\"acceptFriend.jsp?username="+userInfo.pendingFriendRequestsTo.get(i)+"Accept</a> "
                         //          +userInfo.pendingFriendRequestsTo.get(i));

               //     }
                  if(friends!=null&&friends.size()>1)
                      {out.println("Your Friends are "+friends.size()+"</br> ");



                                for(int i=0;i<friends.size();i++){
%>

<li><b>

                    <%out.println("<a href=profile.jsp?username=" + friends.get(i) + ">" + friends.get(i) + "</a></br>");
               }}
               //   if(userInfo.pendingRequestsFromUser().length()>1)
                 //         {for(int i=0;i<userInfo.pendingRequestsFromUser().length();i++)
                   //   out.print("<a href=profile.jsp?username="+userInfo.pendingRequestsFromUser().get(i)+">"+"</a>");
                     //              out.print("These users are not yet sure they want to be your friends");}
               %>

    </b></li>

		<%

               String[] suggestions = userInfo.SuggestFriends();
               if(suggestions!=null)
               if(suggestions.length>=1)
               %><li><% out.print("You should be friends with</br>");
               %></li>><%
                for (int i = 0; i < suggestions.length; i++) {
                    %>

<li><b>
               <%out.print("<a href=profile.jsp?username=" + suggestions[i] + ">" + suggestions[i] + "</a></br>");
                }


            %>
            <a href="manageFriends.jsp">Manage Your Friends</a>
         </b></li>
        <%
     }

    %>       
             </ul>
            <hr>
                comon-popular </br>
                interests list
            <hr>
                </td>
           </tr>
        </table>





</div>
     <div id ="headbar">
            <h1>Abandonware <br/> Place</h1>
            <div id ="searchbar">
            <form action="search.jsp">
   <input type="text" placeholder="search for usernames"/>
   <a href="search.jsp"> Advanced Search</a>
     </form></div>
	</div>
         
        <div id="leftbar" class="sidebox">
        <table style="width:5%;">
           <tr> <td>
                   <a href="profile.jsp"/>
        <hr>
                       <%
            
                out.print("profile pic</a>");
                if(privMode==1)
                   out.println("</br>your personal info</br></br>");
                   else if(privMode==2||privMode==3)
                       out.print("</br></br>Username:</br><h3>"+request.getParameter("username")+"</h3></br>");

                if(name!=null)
                    out.println("NAME </br>"+name);

                if(surname!=null)
                    out.println(surname+"</br></br>");
               // if(interests!=null)
                 //   out.println(interests);
                if(username!=null)
                    out.println("USERNAME</br>"+username+"</br></br>");
              // if(welcomeText!=null)
                //   out.println(welcomeText);
                if(date!=null)
                    out.println(date);
               

              %>
        
      <!--               <b><input type="image" src="imadge/Pixel_Character_6__Yoshi_by_meowmixkitty1.jpg" name="image" width="55" height="55" >
                </b>
          -->
          <%if (privMode==1){%>
             <a href="Pms.jsp">
                <b>Edit</b>
            </a>
         
        <hr />
        <% ArrayList temp=userInfo.getUnreadPms();
                if(!temp.isEmpty())
                {    out.println("<a href=readPms.jsp> You have "+temp.size()+"UnreadPms </a>");%>
            <a href="readPms.jsp">
                <b><input type="image" src="imadge/pms.jpg" name="pms" background-color="#C0C0C0" width="35" height="35" >
               </b>
            </a>
            <hr />
        <%}
%>            <a href="Pms.jsp">Sent A new Pm</a>
 <% }%>
                            
		<%
                if(privMode==1 )
                   {
                    out.print("Interests <ul>");
                                                      
                for(int i=0;i<interests.length;i++)
                    {
                out.print("<li>"+interests[i]+"</li>");
                  }
                out.print("</ul>");
                               }
			%>
            <hr />
                </td>


                   </tr>
        </table>
        
        </div>

                        <div id"mainContainer">
                        <%
                        out.print(userInfo.getSuggestions().toString());
%>

    </div>

        
        <a href="profile.jsp?username=northy">visit northy</a>
<div id="text">
    <%if(privMode==3){
        out.print("<h1>Hello and Welcome to "+stranger.getUsername()+" 's Profile!!!</h1></br>");
    out.print("<h2> Here is what "+stranger.getUsername()+" has to say to you!!!</h2></br>");
    out.print(stranger.getWelcomeText());}
      else if(privMode==2){
        out.print("<h1>Hello and Welcome to "+friend.getUsername()+" 's Profile!!!</h1></br>");
    out.print(" <h2>Here is what "+friend.getUsername()+" has to say to you!!!</h2></br>");
    out.print(friend.getWelcomeText()+"</br></br>");
    out.print("<h2> Here is "+friend.getUsername()+" 's Interests </h2><ul>");
                                                      
                for(int i=0;i<interests.length;i++)
                    {
                out.print("<li>"+interests[i]+"</li>");
                  }
                out.print("</ul>");
                               
		
      }
    %>

<%if(privMode==3){
    out.print("</br>Do you whant to make "+stranger.getUsername()+" your friend?</br>");
    %>
    <a href="addFriend.jsp?username=<%out.print(request.getParameter("username"));%> ">clik me!!</a>
        <%}%>
        </div>

   
    </body>
</html>
